/*
 * FileHelper.hpp
 *
 *  Created on: 31.05.2014
 *      Author: philipp
 */

#ifndef FILEHELPER_HPP_
#define FILEHELPER_HPP_

#include "dirent.h"
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
#include "Misc.hpp"
#include <exception>

/*
 * useful methods for file handling.
 */
namespace FileHelper {

/*
 * Exception thrown on io error.
 */
class IOException: public std::exception {
public:
	const char *what() const noexcept {
		return "There was an IO error.";
	}
};

/*
 * checks if the specified folder exists
 */
bool folderExists(const std::string &folder);

/*
 * stores a cv::mat as image. if normalize is set to true,
 * the image will be normalized to values between 0-255 before saving.
 * This can improve contrast.
 */
void saveScreenshot(const cv::Mat &screenshot, const std::string &fileName,
		bool normalize);

/*
 * reads an image and returns its contents as cv mat.
 */
cv::Mat readImage(const std::string &fileName);

/*
 * reads all images within the specified folder and returns them as vector of cv mat.
 * "type" is the file extention, such as ".jpg".
 */
std::vector<cv::Mat> readImagesInFolder(const std::string &dir,
		const std::string &type);

}

#endif /* FILEHELPER_HPP_ */
